Skip to content

Use Reline::ANSI when ruby is built with the msys/cygwin runtime#910

Open
tompng wants to merge 1 commit into
ruby:masterfrom
tompng:try_fix_903
Open

Use Reline::ANSI when ruby is built with the msys/cygwin runtime#910
tompng wants to merge 1 commit into
ruby:masterfrom
tompng:try_fix_903

Conversation

@tompng

@tompng tompng commented Jul 19, 2026

Copy link
Copy Markdown
Member

A cygwin-built ruby (e.g. MSYS2's ruby package) routes all I/O through the Cygwin tty layer, which presents an ANSI terminal regardless of what stdin is attached to: a Cygwin pty pipe (mintty) or a Windows console (Windows Terminal, conhost). In console mode, Cygwin enables ENABLE_VIRTUAL_TERMINAL_INPUT, so arrow keys arrive as ESC [ A character events instead of VK_UP key events. Reline::Windows reads the console handle directly via ReadConsoleInputW, bypassing the tty layer, and has no CSI key bindings, so arrow keys were ignored.

cygwin/msys were originally not in this branch: until 1cfa522 the condition was RUBY_PLATFORM =~ /mswin|mingw/. That commit switched to the generic "is Windows" host_os regex to support JRuby (whose RUBY_PLATFORM is always "java"); including cygwin/msys was incidental, not motivated by any case where a cygwin ruby needed the console API. JRuby on Windows reports host_os "mswin32" and is unaffected.

Fixes #903

A cygwin-built ruby (e.g. MSYS2's ruby package) routes all I/O through
the Cygwin tty layer, which presents an ANSI terminal regardless of
what stdin is attached to: a Cygwin pty pipe (mintty) or a Windows
console (Windows Terminal, conhost). In console mode, Cygwin enables
ENABLE_VIRTUAL_TERMINAL_INPUT, so arrow keys arrive as ESC [ A
character events instead of VK_UP key events. Reline::Windows reads
the console handle directly via ReadConsoleInputW, bypassing the tty
layer, and has no CSI key bindings, so arrow keys were ignored.

cygwin/msys were originally not in this branch: until 1cfa522 the
condition was `RUBY_PLATFORM =~ /mswin|mingw/`. That commit switched
to the generic "is Windows" host_os regex to support JRuby (whose
RUBY_PLATFORM is always "java"); including cygwin/msys was incidental,
not motivated by any case where a cygwin ruby needed the console API.
JRuby on Windows reports host_os "mswin32" and is unaffected.

Fixes ruby#903

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arrow key inputs are ignored when using MSYS bash with non-Mintty terminals

1 participant